import { SEARCH_HISTORY_KEY } from '@/pages/search/config'
import storage from './storage'
export const searchMixin = {
  methods: {
    $_updateStorage (value) { // 更新缓存
      let history = storage.get(SEARCH_HISTORY_KEY, [])
      if (history.length) { // 过滤掉传入的搜索词
        history = history.filter((item) => {
          return item !== value
        })
      }
      history.unshift(value)// 把传入的搜索词放在第一个位置
      storage.set(SEARCH_HISTORY_KEY, history)
      location.href = `https://s.m.taobao.com/h5?event_submit_do_new_search_auction=1&_input_charset=utf-8&topSearch=1&atype=b&searchfrom=1&action=home%3Aredirect_app_action&from=1&sst=1&n=20&buying=buyitnow&q=${value}`
    }
  }
}
